use OlympusSoftware

drop table [OpportunityVersusImages]
drop table [OpportunityImage]
drop table [Opportunity]

IF NOT EXISTS (SELECT 1 FROM dbo.sysobjects WHERE id = object_id(N'dbo.Opportunity') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [dbo].[Opportunity](
	[OpportunityId] int Primary Key,
	[TitleInfoId] int,
	[DescriptionInfoId] int
)
GO

IF NOT EXISTS (SELECT 1 FROM dbo.sysobjects WHERE id = object_id(N'dbo.OpportunityImage') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [dbo].[OpportunityImage](
	[OpportunityImageId] int Primary Key,
	[Title] nvarchar(128),
	[Contents] image
)
GO

IF NOT EXISTS (SELECT 1 FROM dbo.sysobjects WHERE id = object_id(N'dbo.OpportunityVersusImages') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [dbo].[OpportunityVersusImages](
	[IdOpportunity] int,
	[IdImage] int,
	CONSTRAINT [PK_IdOpportunity_IdImage] PRIMARY KEY ([IdOpportunity], [IdImage]),
	CONSTRAINT [FK_Opportunity] FOREIGN KEY ([IdOpportunity]) REFERENCES [Opportunity]([OpportunityId]),
	CONSTRAINT [FK_OpportunityImage] FOREIGN KEY ([IdImage]) REFERENCES [OpportunityImage]([OpportunityImageId])
)
GO
